Creating a Button with a Bitmap

Description

Button3 uses an Xbasic routine to copy the customer address to the clipboard. Button3 uses a bitmap instead of text to define its purpose.

images/Paste_button.gif

Procedure: Configuring the Button3 Button

The following procedure assumes that the developer has opened the form in the Form Editor. Follow these instructions to create a button similar to Button3 :

  1. Place a button on the form.

  2. On the resulting Define Button dialog box click the Define Picture button.

    images/AL_form_customer_information_button3_create0.gif
  3. Click the Internal combo box to open it up.

    images/AL_form_customer_information_button3_create1.gif
  4. Select the image in the resulting Insert Image dialog box.

  5. Click the System images radio button.

  6. Click the Insert button.

    images/AL_form_customer_information_button3_create2.gif
  7. In the Define Picture dialog box click the OK button.

    images/AL_form_customer_information_button3_create3.gif
  8. In the Define Button dialog box click the Next button.

  9. Click the Launch Script Editor button to display the Code Editor and to start writing Xbasic code (refer to ((|#Button3_OnPush_Event|Button3 OnPush Event)) ).

  10. Close the Code Editor and save your code.

Xbasic Code Run by the Button3 OnPush Event

When the user clicks Button3, Alpha Anywhere runs the following Xbasic code. The code formats the customer name and billing address into a string and copies the string to the system clipboard.

dim tbl as P
t = table.current()
dim address as C
address = trim(tbl.firstname) + " " + trim(tbl.lastname) + crlf()
address = address + tbl.bill_address_1 + crlf()
if (.not. tbl.bill_address_2.is_blank()) then
    address = address + tbl.bill_address_2 + crlf()
end if
address = address + trim(tbl.bill_city) + ", " + trim(tbl.bill_state_region) + " " + tbl.bill_postal_code
:clipboard.set_data(address)

An Explanation of the Code

The first line creates a pointer variable named tbl to refer to table (and the data) that the Customer Information form displays.

dim tbl as P

Each form is based upon a table (or set). The Customer Information form is based on the Customer table. This line points tbl at the Customer table.

tbl = table.current()

The address will be a character string, so we first dim a variable named c.

dim address as C

Define crlf as a carriage return and line feed.

crlf = chr(13) + chr(10)

Add the firstname and lastname to the address string.

address = trim(tbl.firstname) + " " + trim(tbl.lastname) + crlf

Add address_1 to the address string.

address = address + tbl.bill_address_1 + crlf

If address_2 is not blank, add it to the address string.

if (.not. tbl.bill_address_2.is_blank()) then
    address = address + tbl.bill_address_2 + crlf
end if

Add bill_city, bill_state_region, and bill_postal_code to the address string.

address = address + trim(tbl.bill_city) + ", " + trim(tbl.bill_state_region) + " " + tbl.bill_postal_code

Copy the address string to the clipboard.

:clipboard.set_data(address)

See Also